<script lang="ts" setup>
import { bookTypeModel } from '@/api/book/bookType';
import { useRequest } from '@/hooks/useRequest';
import { SelectMixedOption } from 'naive-ui/es/select/src/interface';
import { computed } from 'vue';

interface Props {
  hasEmptyOption?: boolean
}
const props = defineProps<Props>();

const { data } = useRequest(bookTypeModel.records, {
  defaultParmas: [{ pageNum: 1, pageSize: 99999 }]
});

const options = computed<SelectMixedOption[]>(() => {
  const _data = data.value?.list.map((item) => {
    return {
      label: item.typeName,
      value: item.id
    };
  });
  if(props.hasEmptyOption) {
    _data?.unshift({ label: '全部', value: '' } as any);
  }

  return _data;
});
</script>
<template>
  <NSelect
    :options="options"
    placeholder="请选择"
  />
</template>
